IF exists(SELECT * FROM dbo.sysobjects WHERE name='overbrengenStamnummers' AND xtype='P') 
BEGIN
	DROP PROCEDURE overbrengenStamnummers
END
GO

create procedure overbrengenStamnummers
as
update alleGestarteLln
  set stamNrEG = l.stamNr
from leerlingen..leerlingen as l
	left join alleGestarteLln as a
  	  on a.inschrijvingsNr = l.inschrijvingsNr
where (left(l.klas,1) < '3') and not(len(stamNrEG)=7)

update  alleGestarteLln
  set stamNrSR = l.stamNr
  from leerlingen..leerlingen as l
  	left join alleGestarteLln as a
	  on a.inschrijvingsNr = l.inschrijvingsNr
  where (left(l.klas,1) > '2') and not(len(stamNrEG)=7)